<?php
$oldName = $_FILES['file']['name'];
$arr = explode('.',$oldName);
$newName = md5($oldName.time()).'.'.$arr[count($arr)-1];
move_uploaded_file($_FILES['file']['tmp_name'],'error/img/'.$newName);
$img_url = 'error/img/'.$newName;
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <style type="text/css">
        #div1 {
            width: 100px;
            height: 100px;
            background-color: aqua;
        }

        #div2 img {
            width: 100px;
            height: 100px;
        }

        #div1 img {
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
<form action="newupload.php" method="post"enctype="multipart/form-data">
    <h1>用户中心</h1>
    <div id="div1">
        <img src="<?php echo $img_url?>">
    </div>
    <br/>
    <label id="lab1">更改头像</label>&nbsp;&nbsp;
    <input type="file" name="file" id="file" multiple="multiple">
    <div id="div2"></div>
    <div id="div3"></div>
</form>
</body>

<script type="text/javascript">
    var fileObj = document.getElementById('file');
    function showImg() {
        var files = fileObj['files'];
        var URL = window.URL||window.webkitURL;
        var imgURL = URL.createObjectURL(files[0]);
        document.getElementById('div2').innerHTML = `<img src="" id="showImg">`;
        document.getElementById('lab1').innerHTML = `<label id="lab1">头像预览</label>`;
        document.getElementById('div3').innerHTML = `<button id="but1" onclick="OOO();">确定</button>`;
        document.getElementById('showImg').src = imgURL;
    }
    function OOO(){

    }
    function UUU(){
        document.getElementById('div2').innerHTML = ``;
        document.getElementById('lab1').innerHTML = `<label id="lab1">更改头像</label>`;
        document.getElementById('div3').innerHTML = ``;
    }
    onload = function() {
        fileObj.onchange = showImg;

    }
</script>
</html>
<?php
if ($_COOKIE['Token']) {
    echo '<br/>'.'存在COOKIE:' . $_COOKIE['Token'];
} else {
    echo '不存在';
}
?>
